unit u_camera;

interface

uses
  u_input,
  System.Windows.Forms,
  Microsoft.DirectX.DirectInput,
  Microsoft.DirectX.Direct3DX,
  Microsoft.DirectX.Direct3D,
  Microsoft.DirectX,
  u_form;

type

c_camera = class

  private
    myinput : c_input;
    myform : System.windows.Forms.Form;
    myf : c_form;
  public
    function initcam( device: device; width, height:integer; phi, teta, zoom, x, z: double) : integer;

end;


implementation



uses u_mesh,
     u_engine;

function c_camera.initcam( device: device; width, height:integer; phi, teta, zoom, x, z: double) : integer;
var
  posx, posy : single;
begin
  Result := 0 ;

  posx := zoom * sin(teta) + myplayer.get_x;
  posy := zoom * cos(teta) + myplayer.get_y;
  if posx <= 0 then
    begin
      posx := 1;
      Result := 1;
    end;
  if posx >= mymesh.taillex - 1 then
    begin
      posx := mymesh.taillex - 2;
      Result := 1;
    end;
  if posy <= 0 then
    begin
      posy := 1;
      Result := 1;
    end;
  if posy >= mymesh.tailley - 1 then
    begin
      posy := mymesh.tailley - 2;
      Result := 1;
    end;

  if (mymesh.map1[myplayer.etage, trunc(posx), trunc(posy)]._type = 'Mur') then
    begin
      Result := 1;
      posx := posx - 1;
      posy := posy - 1;
    end;

  device.transform.view := matrix.lookatlh(Vector3.Create(posx,zoom - 1.5 ,posy),
                                                          Vector3.Create(myplayer.get_x, 1, myplayer.get_y),
                                                          Vector3.Create(0, 1, 0));
  device.transform.projection := matrix.perspectivefovlh(1,
                                                         width / height,
                                                         0.1,
                                                         15000.0);
  myinput := c_Input.Create;
  myinput := c_input.keyandmousecreate;
  myinput.InitializeKeyboard(myform);
end;

end.
